home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FSEEK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  746 b   |  29 lines

  1. /*  fseek.c, from p. 434 of Turbo C Bible  */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     FILE *infile;
  6.     char filename[80], buffer[81];
  7.     printf("enter name of a text file: ");
  8.     gets(filename);
  9.                 /*  Open the file for reading  */
  10.     if ((infile = fopen(filename, "r")) == NULL)
  11.     {
  12.     printf("fopen failed \n");
  13.     exit(0);
  14.     }
  15.                 /*  Read and display a line  */
  16.     fgets(buffer, 80, infile);
  17.     printf("Line read (before fseek): %s", buffer);
  18.                 /*  Move to beginning using fseek and  */
  19.                 /*  read a line again                  */
  20.     if (fseek(infile, 0L, SEEK_SET) != 0)
  21.     {
  22.     perror("fseek failed!");
  23.     }
  24.     else
  25.     {
  26.     fgets(buffer, 80, infile);
  27.     printf("line read (after fseek) : %s", buffer);
  28.     }
  29. }